home *** CD-ROM | disk | FTP | other *** search
/ PC Format (PL) 2008 February / PC_Format_022008.iso / Internet / Mozilla Thunderbird wtyczki / lightning-0.7-tb-win.xpi / components / calItemModule.js < prev    next >
Encoding:
Text File  |  2007-09-19  |  12.0 KB  |  314 lines

  1. /* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Oracle Corporation code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  *  Oracle Corporation
  19.  * Portions created by the Initial Developer are Copyright (C) 2004
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
  24.  *   Mike Shaver <shaver@off.net>
  25.  *   Matthew Willis <lilmatt@mozilla.com>
  26.  *   Philipp Kewisch <mozilla@kewis.ch>
  27.  *
  28.  * Alternatively, the contents of this file may be used under the terms of
  29.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  30.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  31.  * in which case the provisions of the GPL or the LGPL are applicable instead
  32.  * of those above. If you wish to allow use of your version of this file only
  33.  * under the terms of either the GPL or the LGPL, and not to allow others to
  34.  * use your version of this file under the terms of the MPL, indicate your
  35.  * decision by deleting the provisions above and replace them with the notice
  36.  * and other provisions required by the GPL or the LGPL. If you do not delete
  37.  * the provisions above, a recipient may use your version of this file under
  38.  * the terms of any one of the MPL, the GPL or the LGPL.
  39.  *
  40.  * ***** END LICENSE BLOCK ***** */
  41.  
  42. const kCalRecurrenceInfoContractID = "@mozilla.org/calendar/recurrence-info;1";
  43. const kCalIRecurrenceInfo = Components.interfaces.calIRecurrenceInfo;
  44.  
  45. const kCalRecurrenceRuleContractID = "@mozilla.org/calendar/recurrence-rule;1";
  46. const kCalIRecurrenceRule = Components.interfaces.calIRecurrenceRule;
  47.  
  48. const kCalRecurrenceDateSetContractID = "@mozilla.org/calendar/recurrence-date-set;1";
  49. const kCalIRecurrenceDateSet = Components.interfaces.calIRecurrenceDateSet;
  50.  
  51. const kCalRecurrenceDateContractID = "@mozilla.org/calendar/recurrence-date;1";
  52. const kCalIRecurrenceDate = Components.interfaces.calIRecurrenceDate;
  53.  
  54. /* Constructor helpers, lazily initialized to avoid registration races. */
  55. var CalRecurrenceInfo = null;
  56. var CalRecurrenceRule = null;
  57. var CalRecurrenceDateSet = null;
  58. var CalRecurrenceDate = null;
  59. var CalDateTime = null;
  60. var CalDuration = null;
  61. var CalAttendee = null;
  62. var CalItipItem = null;
  63.  
  64. var componentInitRun = false;
  65. function initBaseComponent()
  66. {
  67.     CalRecurrenceInfo = new Components.Constructor(kCalRecurrenceInfoContractID, kCalIRecurrenceInfo);
  68.     CalRecurrenceRule = new Components.Constructor(kCalRecurrenceRuleContractID, kCalIRecurrenceRule);
  69.     CalRecurrenceDateSet = new Components.Constructor(kCalRecurrenceDateSetContractID, kCalIRecurrenceDateSet);
  70.     CalRecurrenceDate = new Components.Constructor(kCalRecurrenceDateContractID, kCalIRecurrenceDate);
  71.  
  72.     CalDateTime = new Components.Constructor("@mozilla.org/calendar/datetime;1",
  73.                                              Components.interfaces.calIDateTime);
  74.     CalDuration = new Components.Constructor("@mozilla.org/calendar/duration;1",
  75.                                              Components.interfaces.calIDateTime);
  76.     CalAttendee = new Components.Constructor("@mozilla.org/calendar/attendee;1",
  77.                                              Components.interfaces.calIAttendee);
  78.     CalItipItem = new Components.Constructor("@mozilla.org/calendar/itip-item;1",
  79.                                              Components.interfaces.calIItipItem);
  80. }
  81.  
  82.  
  83. /* Update these in calBaseCID.h */
  84. const componentData =
  85.     [
  86.      /* calItemBase and calUtils must be first: later scripts depend on them */
  87.     {cid: null,
  88.      contractid: null,
  89.      script: "calItemBase.js",
  90.      constructor: null},
  91.  
  92.     {cid: null,
  93.      contractid: null,
  94.      script: "calUtils.js",
  95.      constructor: null},
  96.  
  97.     {cid: Components.ID("{f42585e7-e736-4600-985d-9624c1c51992}"),
  98.      contractid: "@mozilla.org/calendar/manager;1",
  99.      script: "calCalendarManager.js",
  100.      constructor: "calCalendarManager",
  101.      onComponentLoad: "onCalCalendarManagerLoad()"},
  102.  
  103.     {cid: Components.ID("{7a9200dd-6a64-4fff-a798-c5802186e2cc}"),
  104.      contractid: "@mozilla.org/calendar/alarm-service;1",
  105.      script: "calAlarmService.js",
  106.      constructor: "calAlarmService",
  107.      service: true},
  108.  
  109.     {cid: Components.ID("{29C56CD5-D36E-453a-ACDE-0083BD4FE6D3}"),
  110.      contractid: "@mozilla.org/calendar/freebusy-service;1",
  111.      script: "calFreeBusyService.js",
  112.      constructor: "calFreeBusyService",
  113.      service: true},
  114.  
  115.     {cid: Components.ID("{4b7ae030-ed79-11d9-8cd6-0800200c9a66}"),
  116.      contractid: "@mozilla.org/calendar/alarm-monitor;1",
  117.      script: "calAlarmMonitor.js",
  118.      constructor: "calAlarmMonitor",
  119.      service: true,
  120.      categories: ["alarm-service-startup", "alarm-service-shutdown"]},
  121.  
  122.     {cid: Components.ID("{974339d5-ab86-4491-aaaf-2b2ca177c12b}"),
  123.      contractid: "@mozilla.org/calendar/event;1",
  124.      script: "calEvent.js",
  125.      constructor: "calEvent"},
  126.  
  127.     {cid: Components.ID("{7af51168-6abe-4a31-984d-6f8a3989212d}"),
  128.      contractid: "@mozilla.org/calendar/todo;1",
  129.      script: "calTodo.js",
  130.      constructor: "calTodo"},
  131.  
  132.     {cid: Components.ID("{5c8dcaa3-170c-4a73-8142-d531156f664d}"),
  133.      contractid: "@mozilla.org/calendar/attendee;1",
  134.      script: "calAttendee.js",
  135.      constructor: "calAttendee"},
  136.  
  137.     {cid: Components.ID("{5f76b352-ab75-4c2b-82c9-9206dbbf8571}"),
  138.      contractid: "@mozilla.org/calendar/attachment;1",
  139.      script: "calAttachment.js",
  140.      constructor: "calAttachment"},
  141.  
  142.     {cid: Components.ID("{04027036-5884-4a30-b4af-f2cad79f6edf}"),
  143.      contractid: "@mozilla.org/calendar/recurrence-info;1",
  144.      script: "calRecurrenceInfo.js",
  145.      constructor: "calRecurrenceInfo"},
  146.  
  147.     {cid: Components.ID("{4123da9a-f047-42da-a7d0-cc4175b9f36a}"),
  148.      contractid: "@mozilla.org/calendar/datetime-formatter;1",
  149.      script: "calDateTimeFormatter.js",
  150.      constructor: "calDateTimeFormatter"},
  151.  
  152.     {cid: Components.ID("{6877bbdd-f336-46f5-98ce-fe86d0285cc1}"),
  153.      contractid: "@mozilla.org/calendar/weektitle-service;1",
  154.      script: "calWeekTitleService.js",
  155.      constructor: "calWeekTitleService"},
  156.  
  157.     {cid: Components.ID("{f41392ab-dcad-4bad-818f-b3d1631c4d93}"),
  158.      contractid: "@mozilla.org/calendar/itip-item;1",
  159.      script: "calItipItem.js",
  160.      constructor: "calItipItem"},
  161.  
  162.     {cid: Components.ID("{9787876b-0780-4464-8282-b7f86fb221e8}"),
  163.      contractid: "@mozilla.org/calendar/itip-processor;1",
  164.      script: "calItipProcessor.js",
  165.      constructor: "calItipProcessor"},
  166.  
  167.     {cid: Components.ID("{1e2fc0e2-bf5f-4d60-9f1e-5e92cf517c0b}"),
  168.      contractid: "@mozilla.org/network/protocol;1?name=webcal",
  169.      script: "calProtocolHandler.js",
  170.      constructor: "calProtocolHandler"},
  171.  
  172.     {cid: Components.ID("{6fe88047-75b6-4874-80e8-5f5800f14984}"),
  173.      contractid: "@mozilla.org/calendar/ics-parser;1",
  174.      script: "calIcsParser.js",
  175.      constructor: "calIcsParser"},
  176.  
  177.     {cid: Components.ID("{207a6682-8ff1-4203-9160-729ec28c8766}"),
  178.      contractid: "@mozilla.org/calendar/ics-serializer;1",
  179.      script: "calIcsSerializer.js",
  180.      constructor: "calIcsSerializer"},
  181.  
  182.     {cid: Components.ID("{40a1ccf4-5f54-4815-b842-abf06f84dbfd}"),
  183.      contractid: "@mozilla.org/calendar/transactionmanager;1",
  184.      script: "calTransactionManager.js",
  185.      constructor: "calTransactionManager"}
  186.     ];
  187.  
  188. var calItemModule = {
  189.     mScriptsLoaded: false,
  190.     loadScripts: function () {
  191.         if (this.mScriptsLoaded)
  192.             return;
  193.  
  194.         const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
  195.         const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
  196.  
  197.         const dirsvcContractID = "@mozilla.org/file/directory_service;1";
  198.         const propsIID = Components.interfaces.nsIProperties;
  199.  
  200.         const iosvcContractID = "@mozilla.org/network/io-service;1";
  201.         const iosvcIID = Components.interfaces.nsIIOService;
  202.  
  203.         var loader = Components.classes[jssslContractID].getService(jssslIID);
  204.         var dirsvc = Components.classes[dirsvcContractID].getService(propsIID);
  205.         var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
  206.  
  207.         // Note that unintuitively, __LOCATION__.parent == .
  208.         // We expect to find the subscripts in ./../js
  209.         var appdir = __LOCATION__.parent.parent;
  210.         appdir.append("js");
  211.  
  212.         for (var i = 0; i < componentData.length; i++) {
  213.             var scriptName = componentData[i].script;
  214.             if (!scriptName)
  215.                 continue;
  216.  
  217.             var f = appdir.clone();
  218.             f.append(scriptName);
  219.  
  220.             try {
  221.                 var fileurl = iosvc.newFileURI(f);
  222.                 loader.loadSubScript(fileurl.spec, null);
  223.             } catch (e) {
  224.                 dump("Error while loading " + fileurl.spec + "\n");
  225.                 throw e;
  226.             }
  227.         }
  228.  
  229.         this.mScriptsLoaded = true;
  230.     },
  231.  
  232.     registerSelf: function (compMgr, fileSpec, location, type) {
  233.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  234.  
  235.         var catman = Components.classes["@mozilla.org/categorymanager;1"]
  236.             .getService(Components.interfaces.nsICategoryManager);
  237.         for (var i = 0; i < componentData.length; i++) {
  238.             var comp = componentData[i];
  239.             if (!comp.cid)
  240.                 continue;
  241.             compMgr.registerFactoryLocation(comp.cid,
  242.                                             "",
  243.                                             comp.contractid,
  244.                                             fileSpec,
  245.                                             location,
  246.                                             type);
  247.  
  248.             if (comp.categories) {
  249.                 var contractid;
  250.                 if (comp.service)
  251.                     contractid = "service," + comp.contractid;
  252.                 else
  253.                     contractid = comp.contractid;
  254.                 for each (var category in comp.categories) {
  255.                     catman.addCategoryEntry(category, "calendar",
  256.                                             contractid, true, true);
  257.                 }
  258.             }
  259.         }
  260.     },
  261.  
  262.     makeFactoryFor: function(constructor) {
  263.         var factory = {
  264.             QueryInterface: function (aIID) {
  265.                 if (!aIID.equals(Components.interfaces.nsISupports) &&
  266.                     !aIID.equals(Components.interfaces.nsIFactory))
  267.                     throw Components.results.NS_ERROR_NO_INTERFACE;
  268.                 return this;
  269.             },
  270.  
  271.             createInstance: function (outer, iid) {
  272.                 if (outer != null)
  273.                     throw Components.results.NS_ERROR_NO_AGGREGATION;
  274.                 return (new constructor()).QueryInterface(iid);
  275.             }
  276.         };
  277.  
  278.         return factory;
  279.     },
  280.  
  281.     getClassObject: function (compMgr, cid, iid) {
  282.         if (!iid.equals(Components.interfaces.nsIFactory))
  283.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  284.  
  285.         if (!this.mScriptsLoaded)
  286.             this.loadScripts();
  287.  
  288.         if (!componentInitRun) {
  289.             initBaseComponent();
  290.             componentInitRun = true;
  291.         }
  292.  
  293.         for (var i = 0; i < componentData.length; i++) {
  294.             if (cid.equals(componentData[i].cid)) {
  295.                 if (componentData[i].onComponentLoad) {
  296.                     eval(componentData[i].onComponentLoad);
  297.                 }
  298.                 // eval to get usual scope-walking
  299.                 return this.makeFactoryFor(eval(componentData[i].constructor));
  300.             }
  301.         }
  302.  
  303.         throw Components.results.NS_ERROR_NO_INTERFACE;
  304.     },
  305.  
  306.     canUnload: function(compMgr) {
  307.         return true;
  308.     }
  309. };
  310.  
  311. function NSGetModule(compMgr, fileSpec) {
  312.     return calItemModule;
  313. }
  314.